<?php echo $this->Html->css('report/report_manager'); ?>
<?php echo $this->Html->css('report/smart_wizard'); ?>
<?php //echo $this->Html->script(array('https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js')); ?>
<?php echo $this->Html->script(array('https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js')); ?>
<?php echo $this->Html->script(array('report/jquery.smartWizard-2.0','report/default')); ?>
<?php echo $this->Form->create('Report',array('target'=>'blank'));?>

<div id="content">
	<!--  start page-heading -->
	<div id="page-heading">
		<h1>Report Manager</h1>
    <?php //echo $this->Html->link("Ticket", array('action' => 'add')); ?>&nbsp;&nbsp;
	</div>
	<!-- end page-heading -->
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized">
        <?php echo $this->Html->image('/images/shared/side_shadowleft.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
    </th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized">
        <?php echo $this->Html->image('/images/shared/side_shadowright.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
    </th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td valign="top">
		<!--  start content-table-inner ...................................................................... START -->
		
			<!--  start table-content  -->

		  <div id="content-table-inner">

            <div id="wizard" class="swMain">
              <ul>
                <li><a href="#step-1">
                      <label class="stepNumber">1</label>
                      <span class="stepDesc">
                         Step 1<br />
                         <small>Select fields</small>
                      </span>
                  </a></li>
                <li><a href="#step-2">
                      <label class="stepNumber">2</label>
                      <span class="stepDesc">
                         Step 2<br />
                         <small>Set the filter</small>
                      </span>
                  </a></li>
                <li><a href="#step-3">
                      <label class="stepNumber">3</label>
                      <span class="stepDesc">
                         Step 3<br />
                         <small>Select order</small>
                      </span>                   
                   </a></li>
                <li><a href="#step-4">
                      <label class="stepNumber">4</label>
                      <span class="stepDesc">
                         Step 4<br />
                         <small>Select style</small>
                      </span>                   
                   </a></li>       
              </ul>
            
              <div id="step-1">   
                  <h2 class="StepTitle">Step 1 Fields</h2>
                    <div class="reportManager index">
                    <?php  
                    echo $this->Element('reports/fields_dnd_table_header',array(
                        'title'=>__('Report Manager'),
                        'sortableClass'=>'sortable1'));
                    
                    if ( isset($this->data[$modelClass]) ) // load from file
                        $currentModelSchema = $this->data[$modelClass];
                    else // new report
                        $currentModelSchema = $modelSchema;
                    
                    echo $this->Element('reports/fields_dnd',array(
                        'modelClass'=>$modelClass,
                        'modelSchema'=>$currentModelSchema));
                    foreach ($associatedModelsSchema as $key => $value) {
                        if ( $associatedModels[$key] == 'hasMany' || $associatedModels[$key] == 'hasAndBelongsToMany' )
                            continue;
                        
                        if ( isset($this->data[$key]) ) // load from file
                            $currentModelSchema = $this->data[$key];
                        else // new report
                            $currentModelSchema = $value;
                        
                        echo $this->Element('reports/fields_dnd',array(
                            'modelClass'=>$key,
                            'modelSchema'=>$currentModelSchema));
                    }
                    echo $this->Element('reports/fields_dnd_table_close');
                    if ( $oneToManyOption != null ) {
                        echo $this->Element('reports/fields_dnd_table_header',array(
                            'title'=>$oneToManyOption,
                            'sortableClass'=>'sortable2'));
                        
                        if ( isset($this->data[$oneToManyOption]) ) // load from file
                            $currentModelSchema = $this->data[$oneToManyOption];
                        else // new report
                            $currentModelSchema = $associatedModelsSchema[$oneToManyOption];
                        

                        echo $this->Element('reports/fields_dnd',array(
                            'modelClass'=>$oneToManyOption,
                            'modelSchema'=>$currentModelSchema)
                            );

                        /*if($oneToManyOption == 'TicketSla'){
                            $currentAssocModelSchema = $associatedModelsSchema['User'];

                            echo $this->Element('reports/fields_dnd',array(
                                'modelClass'=>'User',
                                'modelSchema'=>$currentAssocModelSchema)
                                );
                        }*/

                        echo $this->Element('reports/fields_dnd_table_close');
                    }
                    ?>
            
                    </div>
              </div>
              <div id="step-2">
                  <h2 class="StepTitle">Step 2 Filter</h2> 
                    <?php      
                    echo $this->Element('reports/logical_operator');
                    echo $this->Element('reports/filter',array('modelClass'=>$modelClass,'modelSchema'=>$modelSchema));
                    foreach ($associatedModelsSchema as $key => $value) {
                        if ( $associatedModels[$key] != 'hasMany' && $associatedModels[$key] != 'hasAndBelongsToMany' )            
                            echo $this->Element('reports/filter',array('modelClass'=>$key,'modelSchema'=>$value));
                    }
                    ?> 
              </div>                      
              <div id="step-3">
                  <h2 class="StepTitle">Step 3 Order</h2>   
                    <?php
                    echo $this->Element('reports/order_direction');
                    echo $this->Element('reports/order',array('modelClass'=>$modelClass,'modelSchema'=>$modelSchema));
                    foreach ($associatedModelsSchema as $key => $value) {
                        if ( $associatedModels[$key] != 'hasMany' && $associatedModels[$key] != 'hasAndBelongsToMany' )            
                            echo $this->Element('reports/order',array('modelClass' => $key, 'modelSchema' => $value));
                    }
                    ?> 
              </div>
              <div id="step-4">
                  <h2 class="StepTitle">Step 4 Style</h2>   
                    <?php
                    echo $this->Element('reports/report_style',array('oneToManyOption' => $oneToManyOption));
                    ?> 
              </div>    
            </div>
            <?php echo $this->Form->input('report_created', array('value' => date('m-d-Y h:m:s'), 'type' => 'hidden')); ?>
            <?php echo $this->Element('reports/one_to_many_option',array('oneToManyOption' => $oneToManyOption)); ?> 
            <?php echo $this->Form->end() ;?>

  		</div>
      <!--  end content-table  -->
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
